find_package(PkgConfig)
pkg_check_modules(PC_JPEG  libjpeg)

find_path(JPEG_INCLUDE_DIRS
    NAMES jpeg.h
    HINTS ${PC_JPEG_INCLUDEDIR}
    ${PC_JPEG_INCLUDE_DIRS}
)

find_library(JPEG_LIBRARIES
    NAMES jpeg
    HINTS ${PC_JPEG_LIBDIR}
    ${PC_JPEG_LIBRARY_DIRS}
)

#message("JPEG_LIBRARIES=${JPEG_LIBRARIES} JPEG_INCLUDE_DIRS=${JPEG_INCLUDE_DIRS} PC_JPEG_VERSION=${PC_JPEG_VERSION}")
if(JPEG_INCLUDE_DIRS AND JPEG_LIBRARIES)
    set(JPEG_FOUND TRUE)
    set(JPEG_LIBRARY ${JPEG_LIBRARIES})
    set(JPEG_INCLUDE_DIR ${JPEG_INCLUDE_DIRS})
    set(JPEG_VERSION ${PC_JPEG_VERSION})
endif()

include(FindPackageHandleStandardArgs)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(zlib REQUIRED_VARS JPEG_INCLUDE_DIRS JPEG_LIBRARIES 
#	FOUND_VAR JPEG_FOUND VERSION_VAR JPEG_VERSION)

mark_as_advanced(JPEG_LIBRARIES JPEG_LIBRARY JPEG_INCLUDE_DIRS JPEG_INCLUDE_DIR JPEG_FOUND)

